package com.cn.wanxi.servlet.company;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.util.UpLoad;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/producat/companyUpdate")
public class CompanyUpdateServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");

        UpLoad upLoad=new UpLoad();
        String string=upLoad.imgUpload(req);
        String products[]=string.split("@@");
        String logo = String.valueOf(req.getSession().getAttribute("logo"));
        if (products[0].equals("undefined")){
            products[0]=logo;
        }


        CompanyModel companyModel=new CompanyModel();
        companyModel.setLogo(products[0]);
        companyModel.setEmail(products[1]);
        companyModel.setHotline(products[2]);
        companyModel.setAddress(products[3]);
        companyModel.setPhone(products[4]);
        companyModel.setTel(products[5]);
        companyModel.setLandline(products[6]);


        ICompanyService iCompanyService=new CompanyServiceImpl();

        int count=iCompanyService.update(companyModel);


        JSONObject jsonObject=new JSONObject();
        jsonObject.put("count",count);
        resp.getWriter().println(jsonObject);
    }
}
